package j180.javaoo.homework;

import java.time.LocalDate;
import java.util.Scanner;

/**
 * 编写程序，(Scanner)当以年-月-日的格式输入一个日期时，输出其该年是否为闰年，该月有几天，该日是星期几
 */
public class HomeWork04 {
    public static void main(String args[]){
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入年月日，格式：yyyy-mm-dd");
        String s = scan.next();
        String[] ss = s.split("-");
        int year = Integer.parseInt(ss[0]);
        int m = Integer.parseInt(ss[1]);
        int d = Integer.parseInt(ss[2]);

        if(isLeap(year))
            System.out.println("是闰年");
        else
            System.out.println("不是闰年");

        System.out.println("该月有"+ dayOfMouth(m,isLeap(year))+"天");

        System.out.println("该日是星期"+"七一二三四五六".charAt(week(year, m, d)));


    }

    public static boolean isLeap(int year){
        if(year % 4 == 0){
            if(year % 100 != 0 || year % 400 == 0){
               return true;
            }else{
               return false;
            }
        }else{
            return false;
        }
    }

    public static int dayOfMouth(int mouth, boolean isLeap){
        int days = 0;
        switch (mouth){
            case 1:
            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
            case 12:
                days = 31;
                break;
            case 4:
            case 6:
            case 9:
            case 11:
                days = 30;
                break;
            case 2:
                if(isLeap){
                    days = 29;
                }else{
                    days = 28;
                }
                break;
        }
        return days;
    }

    /**
     * 判断该时期是星期几
     * @param
     * @return 星期几
     */
    public static int week(int year, int m, int d){

        LocalDate ld1 = LocalDate.of(year, m, d);

        LocalDate ld2 = LocalDate.of(2020, 11, 8);

        int days = 0;
        while(true){
            if(ld1.plusDays(days).toString().equals(ld2.toString()) || ld1.minusDays(days).toString().equals(ld2.toString()))
                break;
            else
                days++;
        }

        int week = days % 7;
//        System.out.println(week);
        return week;
    }
}
